package entity;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author: heweiwei
 * @Date: 2022/8/26 10:24
 * @Desc:
 */
public class Test {

    public static void main(String[] args) {

        String key = String.join(":", "1", "NURSE_SAFE_OPEN", "300300");
        System.out.println("key = " + key);



        PrescriptionDetail one = new PrescriptionDetail();
        one.setMedicationName("呋喃硫胺片");
//        one.setOrderGroupNo(3);
        one.setOrderGroupInsideNo(1);


        PrescriptionDetail two = new PrescriptionDetail();
        two.setMedicationName("甲钴胺片(弥可保)(集)");
//        two.setOrderGroupNo(2);
        two.setOrderGroupInsideNo(1);

        PrescriptionDetail three = new PrescriptionDetail();
        three.setMedicationName("复方异丙嗪片（制）");
//        three.setOrderGroupNo(4);
        three.setOrderGroupInsideNo(1);







        List<PrescriptionDetail> list = Arrays.asList(three,two,one);


        list.forEach(v -> {
            v.setOrderGroupNoUuid(StrUtil.nullToDefault(v.getOrderGroupNoUuid(), StrUtil.EMPTY));
            v.setMedicationName(StrUtil.nullToDefault(v.getMedicationName(), StrUtil.EMPTY));
            if (ObjectUtil.isNull(v.getOrderGroupNo())) {
                v.setOrderGroupNo(-1);
            }
            if (ObjectUtil.isNull(v.getOrderGroupInsideNo())) {
                v.setOrderGroupInsideNo(-1);
            }
        });

        List<PrescriptionDetail> sortDetails = list.stream().sorted(Comparator.comparing(PrescriptionDetail::getOrderGroupNoUuid).
                thenComparingInt(PrescriptionDetail::getOrderGroupNo).
                thenComparingInt(PrescriptionDetail::getOrderGroupInsideNo).
                thenComparing(PrescriptionDetail::getMedicationName)).collect(Collectors.toList());
        System.out.println("sortDetails = " + sortDetails.stream().map(PrescriptionDetail::getMedicationName).collect(Collectors.joining(",")));
    }
}
